const express = require("express");
const {isToken} = require("../modules/middleware");
const fs = require("fs");
const path = require("path");
const myRouter = express.Router();
myRouter.get("/login",(req,res)=>{
	res.send("个人登陆")
})
myRouter.get("/my",isToken(),(req,res)=>{
	// if(tokenList.includes(req.query.token))
	// 	res.send("个人中心")
	// else
	// 	res.redirect("/login");
	res.send("个人中心")
})
myRouter.get("/myLog",isToken("/"),(req,res)=>{
	fs.readFile(path.join(__dirname,"/data/index.json"),"utf-8",(err,logList)=>{
		logList = JSON.parse(logList).filter(item=>item.ip === req.socket.remoteAddress)
			.map(item=>(`
				<div>
					<p>id:${item.id}</p>
					<p>访问时间:${item.addTime}</p>
					<p>请求方式:${item.method}</p>
					<p>请求地址:${item.url}</p>
					<p>IP:${item.ip}</p>
				</div>
				<hr/>
			`))
		res.send((`
			<div>
				<h3>您的访问日志：</h3>
				${logList.join("")}
			</div>
		`))
	})
});
module.exports = myRouter;